Skip to content

feat(libCallApi): implement OAuth2 Option A for remote API auth#31

Merged
hmmftg merged 1 commit into
mainfrom
cursor/oauth2-option-a-403e
Jun 17, 2026
Merged

feat(libCallApi): implement OAuth2 Option A for remote API auth#31
hmmftg merged 1 commit into
mainfrom
cursor/oauth2-option-a-403e

Conversation

@hmmftg

@hmmftg hmmftg commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

Implements OAuth2 Option A for outbound remote API authentication in libCallApi using golang.org/x/oauth2 behind the existing AuthSystem / TokenCache abstractions.

Changes

  • Add OAuth2Auth adapter with client_credentials and refresh_token support
  • Refactor AuthSystem to use context.Context and add refresh-first logic in handleToken
  • Add EnsureAuthorization and wire it into PrepareCall, ConsumeRestApi, and ConsumeRestBasicAuthApi
  • Bootstrap OAuth auth from remoteApis.auth.grant-type at app startup
  • Accept both auth-uri and auth-url secure param keys
  • Add unit/integration tests for token fetch, cache, refresh, concurrency, and BasicAuth fallback
  • Document remote API OAuth2 config in README

Config example

remoteApis:
  partner-api:
    domain: https://api.partner.com
    name: partner-api
    auth:
      grant-type: client_credentials
      auth-uri: https://auth.partner.com/oauth/token
      client-id: partner-client

Secure values: remote-api#partner-api#client-secret, client-id, auth-uri

Test plan

  • go test ./libCallApi/... — all tests pass
  • go build ./... — compiles cleanly
Open in Web Open in Cursor 

Add golang.org/x/oauth2 adapter behind AuthSystem with client_credentials
and refresh_token support, thread-safe token caching, and EnsureAuthorization
wired into PrepareCall and legacy ConsumeRest paths. Bootstrap OAuth auth
from remoteApis config at startup and align auth-uri/auth-url secure params.

Co-authored-by: حمید ملک محمدی <hmmftg@gmail.com>
@hmmftg hmmftg marked this pull request as ready for review June 17, 2026 10:53
@hmmftg hmmftg merged commit d376c39 into main Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants